To allocate memory that is shared between the driver and the application process, your drvmap() function must do steps 1 and 2 of the procedure below. To free that memory later, your drvunmap() function must do step 3.
Use the kmem_alloc() kernel function to allocate some memory pages in the kernel:
Map the memory pages into the user's address space by calling v_mapphys():
v_mapphys (vt, kaddr, nbytes)
To free the memory, your driver's unmapping function, drvunmap(), must call kmem_free():
kmem_free(kaddr, len);
kmem_alloc() allocates physical memory and returns a kernel virtual address associated with that memory. The physical memory is not subject to paging. v_mapphys() returns 0 upon success and -1 upon failure. The parameters for these calls are:
vt
Your drvmap() function must give this parameter the opaque handle to the user virtual address space. (The internals of this structure are likely to change from release to release.)
kaddr
Your drvmap() function must give this parameter the virtual address returned by kmem_alloc(). Your drvunmap() function must give this parameter the kernel virtual address returned by kmem_alloc().
len
Your drvmap() function must give this parameter the number of bytes to be mapped. (This value must not be greater than the number of pages allocated in step 1.)